import json
import time
import uuid


class CommonTopicRequest:
    def __init__(self, tid=None, bid=None, timestamp=None, data=None):
        self._tid = str(uuid.uuid4())
        self._bid = str(uuid.uuid4())
        self._timestamp = timestamp
        self._data = data
    def __str__(self):
        return f"CommonTopicRequest(tid='{self._tid}', bid='{self._bid}', timestamp={self._timestamp}, data={self._data})"

    # Getter and Setter for tid
    @property
    def tid(self):
        return self._tid

    @tid.setter
    def tid(self, tid):
        self._tid = tid

    # Getter and Setter for bid
    @property
    def bid(self):
        return self._bid

    @bid.setter
    def bid(self, bid):
        self._bid = bid

    # Getter and Setter for timestamp
    @property
    def timestamp(self):
        return self._timestamp

    @timestamp.setter
    def timestamp(self, timestamp):
        self._timestamp = timestamp

    # Getter and Setter for data
    @property
    def data(self):
        return self._data

    @data.setter
    def data(self, data):
        self._data = data

    def to_json(self):
        return json.dumps({
            "tid": self._tid,
            "bid": self._bid,
            "timestamp": int(time.time() * 1000),
            "data": self._data
        })
